import request from '@/utils/request'

/**
 * 留言板管理 API
 */

/**
 * 获取留言分页列表
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.size - 每页数量
 * @param {string} params.keyword - 搜索关键词
 * @param {string} params.status - 状态筛选
 * @returns {Promise} 留言列表
 */
export const getMessagePage = async (params) => {
  try {
    const response = await request.get('/message/page', { params })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 根据ID获取留言详情
 * @param {number} id - 留言ID
 * @returns {Promise} 留言详情
 */
export const getMessageById = async (id) => {
  try {
    const response = await request.get(`/message/${id}`)
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 删除留言
 * @param {number} id - 留言ID
 * @returns {Promise} 删除结果
 */
export const deleteMessage = async (id) => {
  try {
    const response = await request.delete(`/message/${id}`)
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 批量删除留言
 * @param {Array} ids - 留言ID数组
 * @returns {Promise} 删除结果
 */
export const batchDeleteMessages = async (ids) => {
  try {
    const response = await request.delete('/message/batch', { data: { ids } })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 更新留言状态
 * @param {number} id - 留言ID
 * @param {string} status - 新状态
 * @returns {Promise} 更新结果
 */
export const updateMessageStatus = async (id, status) => {
  try {
    const response = await request.put(`/message/${id}/status`, { status })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 回复留言
 * @param {number} id - 留言ID
 * @param {string} reply - 回复内容
 * @returns {Promise} 回复结果
 */
export const replyMessage = async (id, reply) => {
  try {
    const response = await request.post(`/message/${id}/reply`, { reply })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 获取留言统计信息
 * @returns {Promise} 统计数据
 */
export const getMessageStats = async () => {
  try {
    const response = await request.get('/message/stats')
    return response.data
  } catch (error) {
    throw error
  }
}